import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue'
import store  from '@/store'
const routes = [
  {
   path:'/', redirect:'/home'
  },
  {
   path:'/home',component:Home
  },
  {
    path:'/itemMusic',component:()=>import('@/views/ItemMusic.vue')
  },
  {
    path:'/search',component:()=>import('@/views/Search.vue')
  },
  {
    path:'/login',component:()=>import('@/views/Login.vue')
  },
  {
    path:'/infoUser',
    beforeEnter:(to,from  ,next)=>{
        if(store.state.isLogin ||store.state.token || JSON.parse(localStorage.getItem('token'))){
          next()
        }else{
          next('/login')
        }
    },
    component:()=>import('@/views/InfoUser.vue')
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to)=>{
    if(to.path==='/login'){
      store.commit('updateIsFooterShow',false)
    }else{
      store.commit('updateIsFooterShow',true)
    }
})
export default router
